﻿package _Content{

	// --------------MSN:lation_pan@live.cn  QQ: 3423526------------- //
	import flash.display.MovieClip;
    import _Pan3D.cameras.Camera3D;
	
    import _Pan3D.base.stat_3D;
    import _Pan3D.base.move_3D;
	import _Pan3D.model.M3D_Model_stat3D;
	import _Pan3D.model.M3D_Model_move3D;
	import _Content.scene_data;
	import _Pan3D.core.calculation
	import _Pan3D.base.Object3D

	public class scene_manage  {
		

		public function scene_manage() {

		}
		public static  function _push_3dobj(_obj:Object) {
			var _tempobj:stat_3D = new stat_3D()
			_tempobj._et = _obj.et
			_tempobj._name=_obj.name
			_tempobj._level = _obj.level
			_tempobj.x=_obj.x
			_tempobj.y=_obj.y
			_tempobj.z=_obj.z
			_tempobj.angle_y=_obj.angle_y
			_tempobj._mc = new M3D_Model_stat3D()
			_tempobj._mc._init(scene_data._Cam3D,_tempobj)
            scene_data._all_mc.addChild(_tempobj._mc)
			scene_data._Stat_item.push(_tempobj)
		}
		public static  function _push_3dmove(_obj:Object) {
			var _tempobj:move_3D = new move_3D()
			_tempobj._et = _obj.et
			_tempobj._roadarray=_obj.roadarray
			_tempobj._name=_obj.name
			_tempobj._level = _obj.level
			_tempobj.x=_obj.x
			_tempobj.y=_obj.y
			_tempobj.z=_obj.z
			_tempobj.angle_y=_obj.angle_y
			_tempobj._mc = new M3D_Model_move3D()
			_tempobj._mc._init(scene_data._Cam3D,_tempobj)
            scene_data._all_mc.addChild(_tempobj._mc)
			scene_data._Stat_item.push(_tempobj)
		}
		
		public static function _clik_ground(_obj:Object) {
			var A:Object3D = new Object3D();
			var B:Object3D = new Object3D();
			var C:Object3D = new Object3D();
			A.x=-3
			A.y=0
			A.z = 1
			
			B.x=-3
			B.y=0
			B.z = -1
			
			C.x=3
			C.y=0
			C.z = -1
			
			calculation._math_change_point(A,scene_data._Cam3D)
			calculation._math_change_point(B,scene_data._Cam3D)
			calculation._math_change_point(C,scene_data._Cam3D)
			
			A.x=A.rx
			A.y=A.ry
			A.z=A.rz
			
			B.x=B.rx
			B.y=B.ry
			B.z=B.rz
			
			C.x=C.rx
			C.y=C.ry
			C.z=C.rz
			
			var _D = calculation._get_hit_rec(A, B, C, scene_data._Cam3D, _obj.mousex, _obj.mousey)
			//trace(_D.x, _D.y, _D.z)
			return _D
		}
		
		
		public static function _set_position(_obj:Object) {
	
			for (var i in scene_data._Stat_item) {
			    if (scene_data._Stat_item[i]._name == _obj.name) {
					scene_data._Stat_item[i]._mc._set_new_position(_obj)
					break;
				}
			}
		}
		public static function _set_stat_level() {
			var temp_array:Array= scene_data._Stat_item
			temp_array.sortOn(["_level","rz"],[Array.DESCENDING | Array.NUMERIC,Array.DESCENDING | Array.NUMERIC])
			for (var i in temp_array) {
				scene_data._all_mc.setChildIndex(temp_array[i]._mc,i);
			}
		}
		public static  function _catch_cam(_Cam:Camera3D,_focus_3d) {  //设置镜头坐标  （可以对应左上角的镜红点（运行SWF））
			
			var view_angle_x = _focus_3d.angle_x;
			var view_angle_y = _focus_3d.angle_y - 180;
			var rx = 0;
			var ry = 0;
			//var rz = _Cam3D._distance
			var rz = _Cam._distance;
			var tmp_angle = view_angle_x * Math.PI / 180;
			var tmp_ry = ry;
			ry = (Math.cos(tmp_angle) * tmp_ry - Math.sin(tmp_angle) * rz);
			rz = (Math.sin(tmp_angle) * tmp_ry + Math.cos(tmp_angle) * rz);
			var tmp_angle_y = view_angle_y * Math.PI / 180;
			var tmp_rx = rx;
			rx = (Math.cos(tmp_angle_y) * tmp_rx + Math.sin(tmp_angle_y) * rz);
			rz = (Math.sin(tmp_angle_y) * tmp_rx + Math.cos(tmp_angle_y) * rz);
			_Cam.x = rx + _focus_3d.x;
			_Cam.y = ry + _focus_3d.y;
			_Cam.z = rz + _focus_3d.z;
			
		    _Cam.angle_x = _focus_3d.angle_x;
			_Cam.angle_y = _focus_3d.angle_y;
			
			_Cam.sin_y = Math.sin(_Cam.angle_y *  Math.PI / 180);
			_Cam.cos_y = Math.cos(_Cam.angle_y *  Math.PI / 180);
			_Cam.sin_x = Math.sin(_Cam.angle_x *  Math.PI / 180);
			_Cam.cos_x = Math.cos(_Cam.angle_x *  Math.PI / 180);
	

		}
		

	}
}